﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ServicesSheet_UseCarList2 : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dtpUDate.Text = DateTime.Now.ToShortDateString();
            InitializeComponent();
            SetDatabase(false);
            Master.DataSource = WMaster;


            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "~/Help/ServicesSheet/用车管理.htm";
            master.PageName = "通过申请的用车申请表";
            master.PicUrl = "";
            master.IntiBar();
        }

    }
    private void SetDatabase(bool pIsPostBack)
    {
        string where = " (Services_UseCars.FlowFlag='Z') ";

        string strCardId = this.tbUseCarId.Text;
        string strEmdId = SelUser.EmpName;
        string strCarId = this.QueryCars.BindingValue;
        string strDate = this.dtpUDate.Text;

        if (strCardId == string.Empty) strCardId = "";
        if (strEmdId == string.Empty) strEmdId = "";
        if (strCarId == string.Empty) strCarId = "";
        if (pIsPostBack == false)
        {
            if (strDate == string.Empty || strDate == "")
            {
                strDate = DateTime.Now.ToShortDateString();
            }
        }
        else
        {
            if (strDate == string.Empty) strDate = "";
        }

        if (strCardId.Length > 0)
            where += " AND Services_UseCars.UseCarId=" + strCardId;
        if (strEmdId.Length > 0)
            where += " AND Employees.EmpName like '%" + strEmdId + "%'";
        if (strCarId.Length > 0)
            where += " AND Services_UseCars.CarId=" + strCarId;
        if (strDate.Length > 0)
            where += " AND Services_UseCars.UCDate='" + strDate + "'";
        this.WMaster.SetWhere(where);

    }
    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServicesSheet_UseCarList2));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "ServiceSheet.Services_UseCars";
        this.WMaster.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    protected void WebNavigator1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdPrint")
        {
            string whereIn = "(";
            for (int i = 0; i < this.wgvMaster.Rows.Count; i++)
            {
                CheckBox cbPrint = (CheckBox)this.wgvMaster.Rows[i].FindControl("CheckBox1");
                if (cbPrint.Checked == true)
                {
                    string usecarId = this.wgvMaster.Rows[i].Cells[2].Text;
                    whereIn += usecarId + ",";

                }
            }
            if (whereIn == "(")
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('请在要打印的数据前面打钩！')", true);
                return;
            }
            if (whereIn.EndsWith(","))
            {
                whereIn = whereIn.Remove(whereIn.Length - 1);
            }
            whereIn += ")";
            this.Response.Redirect("UseCarPrint.aspx?printId=" + whereIn);

        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        InitializeComponent();
        SetDatabase(true);
        Master.DataSource = WMaster;

    }

    protected void btnClear_Click(object sender, EventArgs e)
    {
        this.tbUseCarId.Text = "";
        SelUser.EmpName = "";
        this.QueryCars.BindingText = "";
        this.QueryCars.BindingValue = "";
        this.dtpUDate.Text = "";


        InitializeComponent();
        SetDatabase(true);
        Master.DataSource = WMaster;
    }

}
